package com.sxbbc.common.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sxbbc.common.basics.utils.statics.StaticUtils;
import com.sxbbc.common.core.entity.jz.ActivityRedPacket;
import com.sxbbc.common.core.entity.jz.BBusiness;
import com.sxbbc.common.core.enums.ActivityPayEnums;
import com.sxbbc.common.core.mapper.jz.ActivityRedPacketMapper;
import com.sxbbc.common.core.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxbbc.common.core.utils.BasePage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品红包活动信息表 服务实现类
 * </p>
 *
 * @author leehao
 * @since 2019-06-04
 */
@Service
public class ActivityRedPacketServiceImpl extends ServiceImpl<ActivityRedPacketMapper, ActivityRedPacket> implements IActivityRedPacketService {

    @Autowired
    private BBusinessService bBusinessService;

    @Override
    public IPage<ActivityRedPacket> queryRedPacketList(BasePage<ActivityRedPacket> page) {
        if (page.isPaging()) {
            super.page(page);
        }else{
            List<ActivityRedPacket> list = super.list();
            page.setRecords(list);
        }
        for (ActivityRedPacket red : page.getRecords()) {
            //商家名称
            BBusiness bBusiness = bBusinessService.getById(red.getBid());
            red.setBusinessName(bBusiness.getNickNameOn());
            red.setTypeName(ActivityPayEnums.getName(red.getPayType()));
        }
        return page;
    }

    @Override
    public ActivityRedPacket selectOne(String proCode) {
        QueryWrapper<ActivityRedPacket> wrapper = new QueryWrapper<>();
        wrapper.eq("pro_code",proCode).eq("status",StaticUtils.STATUS_YES);
        return super.getOne(wrapper);
    }

}
